﻿<Control x:Class="DataGridExtensionsSample.MultipleChoiceFilter"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="30" d:DesignWidth="30"
         xmlns:dgx="urn:tom-englert.de/DataGridExtensions" 
         x:Name="Control">
  <Control.Template>
    <ControlTemplate>
      <Grid>
        <ToggleButton x:Name="ToggleButton">
          <StackPanel Orientation="Horizontal">
            <TextBlock x:Name="IsFilterActiveMarker" Text="." Margin="0,0,-4,0" Foreground="{Binding ElementName=FilterSymbol, Path=Foreground}" FontWeight="Bold" />
            <Control x:Name="FilterSymbol" Style="{DynamicResource {x:Static dgx:DataGridFilter.IconStyleKey}}" />
          </StackPanel>
        </ToggleButton>
        <Popup d:DataContext="{d:DesignInstance dgx:DataGridFilterColumnControl}"
               x:Name="Popup" IsOpen="{Binding Path=IsChecked, ElementName=ToggleButton, Mode=TwoWay}"
               AllowsTransparency="True" StaysOpen="False">
          <ListBox x:Name="ListBox" ItemsSource="{Binding SourceValues}" SelectionMode="Extended" SelectionChanged="ListBox_SelectionChanged">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <DockPanel>
                  <CheckBox DockPanel.Dock="Left" Margin="3,2" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}"/>
                  <TextBlock Margin="3,2" Text="{Binding}" VerticalAlignment="Center"/>
                </DockPanel>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </Popup>
      </Grid>
      <ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding ElementName=Control, Path=Filter.Items}" Value="{x:Null}">
          <Setter TargetName="IsFilterActiveMarker" Property="Visibility" Value="Hidden"/>
        </DataTrigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Control.Template>
</Control>